<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
<script>

    function isArrayLike( obj ) {
        // 判断obj 是不是一个数组(有无length属性)
        if ( Object.prototype.toString.call( obj ) == '[object Array]' ) {
            return true;
        }
        var length = 'length' in obj && obj.length;
        return typeof length === 'number' && length >= 0;
    }

    function each( arr, callback ) {
        if ( isArrayLike ( arr ) ) {
            for ( var i =0; i < arr.length; i++ ) {
                if ( callback.call( arr[ i ], arr[ i ], i ) === false ) break;
            }
        } else {
            for ( var k in arr ) {
                if ( callback.call( arr[ k ], arr[ k ], k ) ===false ) break;
            }
        }
        return arr;
    }

</script>
</html>